vditor 4.0.2-alpha.11 → 4.0.2-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v4.0.2-alpha.11 - A markdown editor written in TypeScript.
2
+ * Vditor v4.0.2-alpha.12 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v4.0.2-alpha.11 - A markdown editor written in TypeScript.
2
+ * Vditor v4.0.2-alpha.12 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -4799,7 +4799,7 @@ var Vditor = /** @class */ (function () {
4799
4799
  /* harmony export */ Y: () => (/* binding */ Constants),
4800
4800
  /* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
4801
4801
  /* harmony export */ });
4802
- var _VDITOR_VERSION = "4.0.2-alpha.11";
4802
+ var _VDITOR_VERSION = "4.0.2-alpha.12";
4803
4803
 
4804
4804
  var Constants = /** @class */ (function () {
4805
4805
  function Constants() {
@@ -4847,7 +4847,7 @@ var Constants = /** @class */ (function () {
4847
4847
  // 别名
4848
4848
  "js", "ts", "html", "toml", "c#", "bat"
4849
4849
  ];
4850
- Constants.CDN = "https://unpkg.com/vditor@".concat("4.0.2-alpha.11");
4850
+ Constants.CDN = "https://unpkg.com/vditor@".concat("4.0.2-alpha.12");
4851
4851
  Constants.MARKDOWN_OPTIONS = {
4852
4852
  autoSpace: false,
4853
4853
  callout: true,
@@ -7324,7 +7324,7 @@ var processKeydown = function (vditor, event) {
7324
7324
  }
7325
7325
  var range = (0,selection/* getEditorRange */.RN)(vditor);
7326
7326
  var startContainer = range.startContainer;
7327
- if (backspaceEmptyHeading(event, vditor, range)) {
7327
+ if (deleteEmptyHeading(event, vditor, range)) {
7328
7328
  return true;
7329
7329
  }
7330
7330
  if (!fixGSKeyBackspace(event, vditor, startContainer)) {
@@ -8093,7 +8093,7 @@ var wysiwyg_processKeydown_processKeydown = function (vditor, event) {
8093
8093
  }
8094
8094
  var range = (0,selection/* getEditorRange */.RN)(vditor);
8095
8095
  var startContainer = range.startContainer;
8096
- if (backspaceEmptyHeading(event, vditor, range)) {
8096
+ if (deleteEmptyHeading(event, vditor, range)) {
8097
8097
  return true;
8098
8098
  }
8099
8099
  // Android 输入法的编辑面板无法在 contenteditable 中正确处理方向键和 End
@@ -10903,6 +10903,35 @@ var containsPlainText = function (node, marker) {
10903
10903
  return (node.Type === "NodeText" && !!((_a = node.Data) === null || _a === void 0 ? void 0 : _a.includes(marker))) ||
10904
10904
  !!((_b = node.Children) === null || _b === void 0 ? void 0 : _b.some(function (child) { return containsPlainText(child, marker); }));
10905
10905
  };
10906
+ // 百分号编码语法字符和实体中的非保留字符,保持查询参数分隔符和 Markdown 往返语义。
10907
+ var escapeDestination = function (text) {
10908
+ var encode = function (character) { return "%" + character.charCodeAt(0).toString(16).toUpperCase(); };
10909
+ return text.replace(/[\\()<>|]/g, encode).replace(/&(?:#[xX]?)?([a-zA-Z0-9])(?=[a-zA-Z0-9]*;)/g, function (match, character) { return match.slice(0, -1) + encode(character); });
10910
+ };
10911
+ var pasteUnfinishedIRLinkDestination = function (vditor, text) {
10912
+ if (vditor.currentMode !== "ir" || !vditor.lute.IsValidLinkDest(text)) {
10913
+ return false;
10914
+ }
10915
+ var range = (0,selection/* getEditorRange */.RN)(vditor);
10916
+ var block = (0,hasClosest/* hasClosestBlock */.pt)(range.startContainer);
10917
+ if (!block || !block.contains(range.endContainer) ||
10918
+ (0,hasClosest/* hasClosestByAttribute */.Th)(range.startContainer, "data-type", "a") ||
10919
+ (0,hasClosest/* hasClosestByMatchTag */._Y)(range.startContainer, "CODE")) {
10920
+ return false;
10921
+ }
10922
+ var prefix = range.cloneRange();
10923
+ prefix.selectNodeContents(block);
10924
+ prefix.setEnd(range.startContainer, range.startOffset);
10925
+ if (!/(?:^|[^\\])!?\[(?:\\.|[^[\]\\\r\n])+\]\(\s*$/.test(prefix.toString())) {
10926
+ return false;
10927
+ }
10928
+ var destination = document.createTextNode(escapeDestination(text));
10929
+ range.deleteContents();
10930
+ range.insertNode(destination);
10931
+ range.setStartAfter(destination);
10932
+ range.collapse(true);
10933
+ return true;
10934
+ };
10906
10935
  var getPastedLink = function (vditor, text) {
10907
10936
  if (!vditor.lute.IsValidLinkDest(text)) {
10908
10937
  return text;
@@ -10930,9 +10959,7 @@ var getPastedLink = function (vditor, text) {
10930
10959
  selectedText = range.toString();
10931
10960
  }
10932
10961
  var title = (selectedText || text).replace(/[\\`*_[\]!~^=$&<>|:]/g, "\\$&");
10933
- var encode = function (character) { return "%" + character.charCodeAt(0).toString(16).toUpperCase(); };
10934
- // 百分号编码语法字符和实体中的非保留字符,保持查询参数分隔符和 Markdown 往返语义。
10935
- var destination = text.replace(/[\\()<>|]/g, encode).replace(/&(?:#[xX]?)?([a-zA-Z0-9])(?=[a-zA-Z0-9]*;)/g, function (match, character) { return match.slice(0, -1) + encode(character); });
10962
+ var destination = escapeDestination(text);
10936
10963
  return "[".concat(title, "](").concat(destination, ")");
10937
10964
  };
10938
10965
 
@@ -11009,22 +11036,37 @@ var fixGSKeyBackspace = function (event, vditor, startContainer) {
11009
11036
  }
11010
11037
  return true;
11011
11038
  };
11012
- var backspaceEmptyHeading = function (event, vditor, range) {
11013
- if (event.key !== "Backspace" || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey ||
11014
- event.defaultPrevented || !range.collapsed) {
11039
+ var deleteEmptyHeading = function (event, vditor, range) {
11040
+ if ((event.key !== "Backspace" && (event.key !== "Delete" || range.collapsed)) ||
11041
+ event.ctrlKey || event.metaKey || event.shiftKey || event.altKey || event.defaultPrevented) {
11015
11042
  return false;
11016
11043
  }
11017
11044
  var heading = (0,hasClosestByHeadings/* hasClosestByHeadings */.c)(range.startContainer);
11018
- if (!heading) {
11045
+ if (!heading || !heading.contains(range.endContainer)) {
11019
11046
  return false;
11020
11047
  }
11021
- var firstElement = heading.firstElementChild;
11022
- var marker = (firstElement === null || firstElement === void 0 ? void 0 : firstElement.getAttribute("data-type")) === "heading-marker" ? firstElement : null;
11023
- var empty = Array.from(heading.childNodes).every(function (node) { return node === marker ||
11024
- node.nodeName === "BR" || node.nodeName === "WBR" ||
11025
- (node.nodeType === Node.TEXT_NODE && node.textContent.split(constants/* Constants */.Y.ZWSP).join("").trim() === ""); });
11026
- if (!empty) {
11027
- return false;
11048
+ var isEmpty = function (nodes) { return Array.from(nodes).every(function (node) {
11049
+ return (node.nodeType === Node.ELEMENT_NODE && node.getAttribute("data-type") === "heading-marker") ||
11050
+ node.nodeName === "BR" || node.nodeName === "WBR" ||
11051
+ (node.nodeType === Node.TEXT_NODE && node.textContent.split(constants/* Constants */.Y.ZWSP).join("").trim() === "");
11052
+ }); };
11053
+ if (range.collapsed) {
11054
+ if (!isEmpty(heading.childNodes)) {
11055
+ return false;
11056
+ }
11057
+ }
11058
+ else {
11059
+ var remainder = range.cloneRange();
11060
+ remainder.selectNodeContents(heading);
11061
+ remainder.setEnd(range.startContainer, range.startOffset);
11062
+ if (!isEmpty(remainder.cloneContents().childNodes)) {
11063
+ return false;
11064
+ }
11065
+ remainder.selectNodeContents(heading);
11066
+ remainder.setStart(range.endContainer, range.endOffset);
11067
+ if (!isEmpty(remainder.cloneContents().childNodes)) {
11068
+ return false;
11069
+ }
11028
11070
  }
11029
11071
  var paragraph = heading.ownerDocument.createElement("p");
11030
11072
  paragraph.setAttribute("data-block", "0");
@@ -12588,6 +12630,12 @@ var paste = function (vditor, event, callback) { return fixBrowserBehavior_await
12588
12630
  case 9: return [3 /*break*/, 11];
12589
12631
  case 10:
12590
12632
  if (textPlain.trim() !== "" && files.length === 0) {
12633
+ if (pasteUnfinishedIRLinkDestination(vditor, textPlain)) {
12634
+ // 结束括号输入后由即时渲染重新解析整条链接。
12635
+ vditor.wysiwyg.triggerRemoveComment(vditor);
12636
+ execAfterRender(vditor);
12637
+ return [2 /*return*/];
12638
+ }
12591
12639
  textPlain = getPastedLink(vditor, textPlain);
12592
12640
  if (pasteIntoTable(vditor, "", textPlain)) {
12593
12641
  // 单元格填充与普通粘贴共用后续规范化和撤销记录。